package com.palfund.send;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        menu.add(Menu.NONE, 1, 1, "sendPermission");
        menu.add(Menu.NONE, 2, 1, "send");
        return super.onCreateOptionsMenu(menu);

    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case 1:
                Intent permission = new Intent();
                permission.setAction("com.palfund.broadcast.receive");
                permission.putExtra("info", "send");
                sendOrderedBroadcast(permission, "com.palfund.send.receive");
                Toast.makeText(this, "发送", Toast.LENGTH_SHORT).show();
                break;
            case 2:
                Intent intent = new Intent();
                intent.setAction("com.palfund.broadcast.receive");
                intent.putExtra("info", "send");
                sendBroadcast(intent);
                Toast.makeText(this, "发送", Toast.LENGTH_SHORT).show();
                break;
        }
        return super.onOptionsItemSelected(item);
    }
}
